/**
 * Copyright 2012
 * VAN
 */
package vaidyaa.algorithms.sorting;

/**
 * @author vaidyaa
 * 
 */
public class BubbleSortService implements SortService {

	@Override
	public void sort(Integer[] array, boolean order) {
		if (array.length <= 1) {
			return;
		}
		boolean isChanged = true;
		while (isChanged) {
			isChanged = false;
			for (int i = 1; i < array.length; i++) {
				
				if (SortingCommons.compare(array[i-1],array[i],order)) {
					Integer temp = array[i -1];
					array[i-1] = array[i];
					array[i] = temp;
					isChanged = true;
				}
			}
			
		}
	}
}
